CMAKE_MINIMUM_REQUIRED(VERSION 3.0)

if (MSVC)
else()
	add_compile_options(-std=c++11)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated")
endif()

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

find_package(Qt5Widgets REQUIRED)


include_directories(${COMN_DIR}/include)
include_directories(.)

link_directories(${PROJECT_ROOT}/lib)
link_directories(${COMN_DIR}/lib)

include_directories(${OPENCV_INCLUDE})
link_directories(${OPENCV_LIBRARY_DIR})

include_directories(${PROJECT_ROOT}/http)
include_directories(${PROJECT_ROOT}/cvutil)

aux_source_directory(. SOURCES)

add_executable(HeadCounter WIN32 ${SOURCES} HeadCounter.qrc HeadCounter.rc)

target_link_libraries(HeadCounter Qt5::Widgets Qt5::Core
	${LIB_PLATFORM}
	${OPENCV_LIBRARIES}
	debug comnd optimized comn
	debug httpd optimized http
	)

set(VERSION_MAJOR "1")
set(VERSION_MINOR "0")
set(VERSION_PATCH "0")
	
install(TARGETS HeadCounter DESTINATION .)

install(FILES ${PROJECT_ROOT}/setup/HeadCounter.ini DESTINATION .)

install(FILES ${PROJECT_ROOT}/setup/1.ini DESTINATION .)
install(FILES ${PROJECT_ROOT}/setup/2.ini DESTINATION .)
install(FILES ${PROJECT_ROOT}/setup/3.ini DESTINATION .)
install(FILES ${PROJECT_ROOT}/setup/Carriage.png DESTINATION .)

if(WIN32)
	install(FILES ${OPENCV_DIR}/x86/vc14/bin/opencv_core341.dll DESTINATION .)
	install(FILES ${OPENCV_DIR}/x86/vc14/bin/opencv_highgui341.dll DESTINATION .)
	install(FILES ${OPENCV_DIR}/x86/vc14/bin/opencv_imgcodecs341.dll DESTINATION .)
	install(FILES ${OPENCV_DIR}/x86/vc14/bin/opencv_imgproc341.dll DESTINATION .)
	install(FILES ${OPENCV_DIR}/x86/vc14/bin/opencv_video341.dll DESTINATION .)
	install(FILES ${OPENCV_DIR}/x86/vc14/bin/opencv_videoio341.dll DESTINATION .)

	install(FILES ${CMAKE_PREFIX_PATH}/bin/Qt5Core.dll DESTINATION .)
	install(FILES ${CMAKE_PREFIX_PATH}/bin/Qt5Gui.dll DESTINATION .)
	install(FILES ${CMAKE_PREFIX_PATH}/bin/Qt5Widgets.dll DESTINATION .)
	
	install(FILES ${PROJECT_ROOT}/setup/platforms/qwindows.dll DESTINATION platforms)
else()
	
endif()

set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
include(InstallRequiredSystemLibraries)

#set(CPACK_PACKAGE_DIRECTORY ${PROJECT_ROOT})
set(CPACK_PACKAGE_NAME "HeadCounter")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "HeadCounter app")
set(CPACK_PACKAGE_VENDOR "www.100wits.com")
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})

if(UNIX)
	SET(CPACK_GENERATOR "TGZ")
else()
	SET(CPACK_GENERATOR "ZIP")
endif()

set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/../dist") 
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") 

include(CPack)